//
//  XMZanTableViewCell.m
//  XunMi
//
//  Created by MacBook on 2024/4/7.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMZanTableViewCell.h"
#import "XMDynamicModel.h"
#import <YBImageBrowser/YBImageBrowser.h>
#import <YBImageBrowser/YBIBVideoData.h>

@interface XMZanTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImgV;
@property (weak, nonatomic) IBOutlet UILabel *nameLa;
@property (weak, nonatomic) IBOutlet UILabel *dateLa;
@property (weak, nonatomic) IBOutlet UILabel *contentLa;
@property (weak, nonatomic) IBOutlet UIImageView *imgV;
@property (weak, nonatomic) IBOutlet UIView *coverV;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *laTrailing;

@end

@implementation XMZanTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setModel:(XMDynamicModel *)model {
    _model = model;
    [self.headImgV sd_setImageWithURL:kStringToUrl(model.avatar.file_url) placeholderImage:model.gender == 1 ? kManHeadImg : kWomanHeadImg];
    self.nameLa.text = model.nickname;
    self.dateLa.text = model.release_time;
    self.contentLa.text = model.content;
    
    switch (model.xmModule) {
        case 1:
            self.imgV.hidden = YES;
            self.laTrailing.constant = 20;
            self.coverV.hidden = YES;
            break;
        case 2:
            self.imgV.hidden = NO;
            self.laTrailing.constant = 20 + 48 + 10;
            self.coverV.hidden = YES;
            [self.imgV sd_setImageWithURL:kStringToUrl(model.resource.firstObject.file_url) placeholderImage:kDefaultCoverImg];
            break;
        case 3:
            self.imgV.hidden = NO;
            self.laTrailing.constant = 20 + 48 + 10;
            self.coverV.hidden = NO;
            [self.imgV sd_setImageWithURL:kStringToUrl(model.resource.firstObject.video_cover) placeholderImage:kDefaultCoverImg];
            break;
        default:
            break;
    }
    
}
- (IBAction)show:(UIButton *)sender {
    if (self.model.xmModule != 1 && self.model.resource.count > 0) {
        __block NSMutableArray *datas = [NSMutableArray array];
        [self.model.resource enumerateObjectsUsingBlock:^(XMFileModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            // 网络图片
            if (obj.file_type == XMFileTypeImage) {
                YBIBImageData *data = [YBIBImageData new];
                data.imageURL = [NSURL URLWithString:obj.file_url];
                data.projectiveView = self.imgV;
                [datas addObject:data];
            }
            if (obj.file_type == XMFileTypeImageVideo) {
                YBIBVideoData *data = [YBIBVideoData new];
                data.videoURL = [NSURL URLWithString:obj.file_url];
                data.projectiveView = self.imgV;
                [datas addObject:data];
            }
            
        }];
        YBImageBrowser *browser = [YBImageBrowser new];
        browser.dataSourceArray = datas;
        browser.currentPage = 0;
        [browser show];
    }
}

@end
